home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / strings.swg / 0131_Formatting Numbers.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  537 b   |  26 lines

  1.  
  2. This function will add commas to a longint.
  3.  
  4. function FormatNumber(l: longint): string;
  5. var
  6.   len, count: integer;
  7.   s: string;
  8. begin
  9.   str(l, s);
  10.   len := length(s);
  11.   for count := ((len - 1) div 3) downto 1 do
  12.     begin
  13.       insert(',', s, len - (count * 3) + 1);
  14.       len := len + 1;
  15.     end;
  16.   FormatNumber := s;
  17. end;
  18.  
  19. And if you are using Delphi, there is, of course, the easy way:
  20.  
  21. function FormatNumber(l: longint): string;
  22. begin
  23.   FormatNumber := FormatFloat('#,##0', StrToFloat(IntToStr(l)));
  24. end;
  25.  
  26.